package cn.jiyun.user.controller;

import cn.jiyun.user.pojo.Users;
import cn.jiyun.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/addUser")
    public String addUser(Users users){
        userService.addUser(users);
        return "ok";
    }
    /**
     * 页面跳转
     */
    @RequestMapping("/{page}")
    public String showPage(@PathVariable String page) {
        return page;
    }

    /**
     * 查询全部用户
     */
    @RequestMapping("/list")
    public String listUser(Model model) {
        List<Users> usersList= userService.findAll();
        model.addAttribute("list",usersList);
        return "list";
    }
}
